namespace designpatternsplusplus.regressions
{
    #region

    using System;
    using decorator;
    using designpatternsplus.contracts;
    using NUnit.Framework;

    #endregion

    [TestFixture]
    public class mainregressions
    {        
        static void SinkEvents()
        {
            CoolCrapMarket.OnPostSaleTransaction +=
                stringIn => Console.WriteLine(Environment.NewLine + stringIn);
            CoolCrapMarket.OnTraceDetailMessage +=
                stringIn => Console.WriteLine("=> TRACE : " + stringIn);
        }

        [Test(Description = "Test Case 1"), Category("Smoke")]
        public void should_provide_proof_for_regression_1()
        {
            // This event recieves the reciept

            SinkEvents();

            using (var myBasket = CoolCrapMarket.Get.ShoppingCart)
            {
                myBasket.AddOne(ItemCategory.NietzcheThusSpoke);
                myBasket.AddOne(ItemCategory.TheSmithsLouderThanBombsMusicCd);
                myBasket.AddOne(ItemCategory.HersheysCandyBar);

                // Note - We also get an event with the receipt in String format
                var myReceipt = CoolCrapMarket.Checkout(myBasket);
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalTax, 1.50, "Tax");
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalSale, 29.83, "Sale");
                myReceipt.Validate(false, 12.49, 16.49, 0.85);
            }
        }

        /// <summary>       
        /// Input 2:
        /// 1 imported box of chocolates at 10.00
        /// 1 imported bottle of perfume at 47.50
        /// 
        /// 2:
        /// 1 imported box of chocolates: 10.50
        /// 1 imported bottle of perfume: 54.65
        /// Sales Taxes: 7.65
        /// Total: 65.15
        /// 
        ///   </summary>
        [Test(Description = "Test Case 2"), Category("Smoke")]
        public void should_provide_proof_for_regression_2()
        {
            SinkEvents();

            using (var myBasket = CoolCrapMarket.Get.ShoppingCart)
            {
                myBasket.AddOne(ItemCategory.PerfumeTopFrenchBrand);
                myBasket.AddOne(ItemCategory.ChocolateInBoxPieces);

                // Note - We also get an event with the receipt in String format
                var myReceipt = CoolCrapMarket.Checkout(myBasket);
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalTax, 7.65, "Tax");
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalSale, 65.15, "Sale");

                myReceipt.Validate(false, 54.65, 10.50);
            }
        }

        /// <summary>      
        /// 1 imported bottle of perfume at 27.99
        /// 1 bottle of perfume at 18.99
        /// 1 packet of headache pills at 9.75
        /// 1 box of imported chocolates at 11.25
        /// </summary>
        [Test(Description = "Test Auto Scanner for a Cart - Uses Radio Frequency Scan"), Category("Smoke")]
        public void should_provide_proof_for_regression_3()
        {
            // Not required, but I wanted to show the Dispose and Using
            // as illustration of basic resource management
            SinkEvents();

            using (var myBasket = CoolCrapMarket.Get.ShoppingCart)
            {

                // Scanner scans your basket discovering
                // anything inside

                myBasket.AutoScanDiscover(new[] {"75173395EB274d7bB51B149E8144B6FE","5FB5B42F99954d7186CDCF5AC26C2FD3",
                    "0FBE1DD511F243acBF6099B929A595BD",
                    "A77727F541604a0cBDD416689E486869"});        

                // Note - We also get an event with the receipt in String format
                var myReceipt = CoolCrapMarket.Checkout(myBasket);
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalTax, 6.70, "Tax");
                RegressionModel.ToViewWithAssert(() => myReceipt.TotalSale, 74.68, "Sale");
                myReceipt.Validate(false, 32.19, 20.89, 9.75, 11.85);
            }
        }
    }
}